#!/usr/bin/env python
# -*- coding: utf-8 -*-

class EventDispatcher:
    
    def __init__(self):
        self._event={}
        
        
    def addEventListener(self, event, function, *arg):
        
        if not hasattr(self, '_event'):
            self._event={}
        if not self._event.has_key(event):
            self._event[event]={}
        self._event[event][function]=arg
        
    def removeEventListener(self, eventType, function=None):
        if function:
            del self._event[eventType][function]
        else:
            del self._event[eventType]
    
    def dispatchEvent(self, eventClass):
        if not hasattr(self, '_event'):
            self._event={}
        eventClass.caller=self
        if self._event.has_key(eventClass.type):
            for ind in self._event[eventClass.type]:
                evt=eventClass#.clone()
                #evt.arg=self._event[eventClass.type][ind]
                ind(evt)
        
    def destroy():
        self._event={}